<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改宿舍检查记录')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-sushe-edit" th:object="${nczxSusheMain}">
            <h4 class="form-header h4">宿舍检查信息</h4>
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-2 control-label">周名称：</label>
                <div class="col-sm-2">
                    <select name="weekname" class="form-control m-b" th:with="type=${@dict.getType('sys_week_name')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{weekname}"></option>
                    </select>
                </div>
                <label class="col-sm-2 control-label">周数：</label>
                <div class="col-sm-2">
                    <select name="weeknum" class="form-control m-b" th:with="type=${@dict.getType('sys_week_num')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{weeknum}"></option>
                    </select>
                </div>
                <label class="col-sm-2 control-label">检查人：</label>
                <div class="col-sm-2">
                    <input name="checkedBy" th:field="*{checkedBy}" class="form-control" type="text">
                </div>
            </div>
            <h4 class="form-header h4">宿舍检查明细信息</h4>
            <div class="row">
                <div class="col-sm-12">
                    <button type="button" class="btn btn-success btn-sm" onclick="addColumn()"><i class="fa fa-plus"> 增加</i></button>
                    <button type="button" class="btn btn-danger btn-sm" onclick="sub.delColumn()"><i class="fa fa-minus"> 删除</i></button>
                    <div class="col-sm-12 select-table table-striped">
                        <table id="bootstrap-table"></table>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: datetimepicker-css" />
    <script th:inline="javascript">
        var prefix = ctx + "nczxsushe/sushe";
        var gradeDatas = [[${@dict.getType('sys_grade_num')}]];
        var sexDatas = [[${@dict.getType('sys_user_sex')}]];
        $("#form-sushe-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-sushe-edit').serialize());
            }
        }

        $(function() {
            var options = {
                data: [[${nczxSusheMain.nczxSusheSubList}]],
                pagination: false,
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                sidePagination: "client",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'grade',
                    align: 'center',
                    title: '年级',
                    width:"110",
                    formatter: function(value, row, index) {
                        var name = $.common.sprintf("nczxSusheSubList[%s].grade", index);
                        return $.common.dictToSelect(gradeDatas, value, name);
                    }
                },
                {
                    field: 'stuclass',
                    align: 'center',
                    title: '班级',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='nczxSusheSubList[%s].stuclass' value='%s'>", index, value);
                        return html;
                    }
				},
                {
                    field: 'room',
                    align: 'center',
                    title: '宿舍号',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='nczxSusheSubList[%s].room' value='%s'>", index, value);
                        return html;
                    }
				},
                {
                    field: 'bad',
                    align: 'center',
                    title: '床号',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='nczxSusheSubList[%s].bad' value='%s'>", index, value);
                        return html;
                    }
				},
                {
                    field: 'sex',
                    align: 'center',
                    title: '性别',
                    width: "80",
                    formatter: function(value, row, index) {
                        var name = $.common.sprintf("nczxSusheSubList[%s].sex", index);
                        return $.common.dictToSelect(sexDatas, value, name);
                    }
				},
                {
                    field: 'standard',
                    align: 'center',
                    title: '扣分标准',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='nczxSusheSubList[%s].standard' value='%s'>", index, value);
                        return html;
                    }
				},
                {
                    field: 'standardreason',
                    align: 'center',
                    title: '扣分原因',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='nczxSusheSubList[%s].standardreason' value='%s'>", index, value);
                        return html;
                    }
				},
                {
                    field: 'checkdate',
                    align: 'center',
                    title: '检查日期',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' id='checkdate' type='text' name='nczxSusheSubList[%s].checkdate' value='%s' readonly />", index, value);
                        return html;
                    }
				}]
            };
            $.table.init(options);
        });

        function addColumn() {
            var count = $("#" + table.options.id).bootstrapTable('getData').length;
            sub.editColumn();
        	
            $("#" + table.options.id).bootstrapTable('insertRow', {
                index: count,
                row: {
                    index: $.table.serialNumber(count),
                    grade: "",
                    stuclass: "",
                    room: "",
                    bad: "",
                    sex: "",
                    standard: "",
                    standardreason: "",
                    checkdate: "",
                    createTime: "",
                    updateTime: "",
                    createBy: ""
        	    }
            });
        };
        $("#bootstrap-table").on("post-body.bs.table", function (e, args) {
            $("input[name$='date']").datetimepicker({
                format: "yyyy-mm-dd",
                minView: "month",
                autoclose: true,
                pickerPosition:'top-right',
                endDate:new Date()
            });
        });
    </script>
</body>
</html>